#region Usings

using System.Collections.Generic;
using Karma.Framework.Core.Domain.Tools.Import.Layout;
using Karma.Framework.Core.Domain.Tools.Import.Report;

#endregion

namespace Karma.Framework.Core.Domain.Tools.Import.Data
{
    delegate void BeforePersistAllEntitiesEventHandler(object o, BeforePersistAllEntitiesEventArgs e);

    internal delegate void AfterPersistAllEntitiesEventHandler(object o, AfterPersistAllEntitiesEventArgs e);

    internal delegate void BeforePersistEntityEventHandler(object o, BeforePersistEntityEventArgs e);

    internal delegate void AfterPersistEntityEventHandler(object o, AfterPersistEntityEventArgs e);

    internal delegate void BeforeUpdateEntityEventHandler(object o, BeforeUpdateEntityEventArgs e);

    internal delegate void AfterUpdateEntityEventHandler(object o, AfterUpdateEntityEventArgs e);

    public abstract class EntityPersisterBase : IEntityPersister
    {
        public abstract OperationsSummary Persist<T>(EntityLayout layout, IList<T> entities) where T : DomainObject;

        #region internal event management

        internal event BeforePersistAllEntitiesEventHandler BeforePersistAll;

        internal event AfterPersistAllEntitiesEventHandler AfterPersistAll;

        internal event BeforePersistEntityEventHandler BeforePersistEntity;

        internal event AfterPersistEntityEventHandler AfterPersistEntity;

        internal event BeforeUpdateEntityEventHandler BeforeUpdateEntity;

        internal event AfterUpdateEntityEventHandler AfterUpdateEntity;

        protected virtual void OnBeforePersistAll(BeforePersistAllEntitiesEventArgs e)
        {
            if (BeforePersistAll != null)
                BeforePersistAll(this, e);
        }

        protected virtual void OnAfterPersistAll(AfterPersistAllEntitiesEventArgs e)
        {
            if (AfterPersistAll != null)
                AfterPersistAll(this, e);
        }

        protected virtual void OnBeforePersistEntity(BeforePersistEntityEventArgs e)
        {
            if (BeforePersistEntity != null)
                BeforePersistEntity(this, e);
        }

        protected virtual void OnAfterPersistEntity(AfterPersistEntityEventArgs e)
        {
            if (AfterPersistEntity != null)
                AfterPersistEntity(this, e);
        }

        protected virtual void OnBeforeUpdateEntity(BeforeUpdateEntityEventArgs e)
        {
            if (BeforeUpdateEntity != null)
                BeforeUpdateEntity(this, e);
        }

        protected virtual void OnAfterUpdateEntity(AfterUpdateEntityEventArgs e)
        {
            if (AfterUpdateEntity != null)
                AfterUpdateEntity(this, e);
        }

        #endregion
    }
}